package org.carabiner.infinitest.depgraph;

import org.junit.Test;
import org.junit.internal.runners.TestIntrospector;

public class TestCaseVerifier implements TestVerifier
{
  public boolean isATest(Class clazz)
  {
    if (clazz == null)
      return false;
    if (isJUnit4TestCase(clazz))
      return true;
    if (clazz.getSuperclass() == null)
      return false;
    if (isJUnit3TestCase(clazz))
      return true;
    return false;
  }

  private boolean isJUnit4TestCase(Class clazz)
  {
    TestIntrospector introspector = new TestIntrospector(clazz);
    return introspector.getTestMethods(Test.class).size() > 0;
  }

  public static boolean isJUnit3TestCase(Class clazz)
  {
    return junit.framework.TestCase.class.isAssignableFrom(clazz);
  }
}
